package com.example.zuoye.mvp.model;

import com.example.mylibrary.http.RetrofitManager;
import com.example.mylibrary.http.RetrofitManager1;
import com.example.mylibrary.mvp.model.BaseModel;
import com.example.zuoye.api.APi;
import com.example.zuoye.bean.PostBodyBean;
import com.example.zuoye.bean.TagTravel;
import com.example.zuoye.mvp.contract.PostContract;
import com.google.gson.JsonObject;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class PostModel extends BaseModel implements PostContract.Model {
    @Override
    public void requestBody(Observer<List<PostBodyBean>> observer) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("page",1);
        jsonObject.addProperty("userId",0);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
        RetrofitManager1.getInstance().getRetrofit().create(APi.class)
                .body(requestBody)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(observer);
    }

    @Override
    public void requestForm(Observer<List<TagTravel>> observer) {
        RetrofitManager.getInstance().getRetrofit().create(APi.class)
                .form(1,2)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(observer);
    }
}
